<div class="section">

	<div class="section-title"><?php echo $this->document->title?></div>
    
    <div class="section-content">
    	
        <form action="" method="post" id="frm_listcar">
        	<div id="ben-search">
            	<label>Số xe</label>
                <input type="text" id="carnumber" name="carnumber" class="text" value="" />
                
                
                <br />
                <input type="button" class="button" name="btnSearch" value="Tìm" onclick="searchForm()"/>
                <input type="button" class="button" name="btnSearch" value="Xem tất cả" onclick="viewAll()"/>
            </div>
        	<div class="button right">
            	<?php if($this->user->checkPermission("gara/car/insert")==true){ ?>
                <input class="button" value="Thêm" type="button" onclick="showCarForm(0,'searchForm()')">
                <?php } ?>
            	<?php if($dialog==true){ ?>
            	
                
                
                <?php }else{ ?>
                
               
                
                <?php if($this->user->checkPermission("gara/car/delete")==true){ ?>
            	<input class="button" type="button" name="delete_all" value="Xóa" onclick="deleteitem()"/>
                <?php } ?>
                <?php } ?>
            </div>
            <div class="clearer">^&nbsp;</div>
            
            <div id="listmovie" class="sitemap treeindex">
                
            </div>
        	
        
        </form>
        
    </div>
    
</div>
<script language="javascript">
function showCarForm(id,strFun)
{
	$('body').append('<div id="carformpopup" style="display:none"></div>');
	var eid = "#carformpopup";
    $(eid).attr('title','Chọn xe');
		$( eid ).dialog({
			autoOpen: false,
			show: "blind",
			hide: "explode",
			width: 900,
			height: 600,
			modal: true,
			buttons: {
				
				
				
				'Lưu':function()
				{
					
					$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	
					$.post("?route=gara/car/save",$('#frm_car').serialize(),
						function(data){
							var arr = data.split("-");
							if(arr[0] == "true")
							{
								//window.location = "?route=core/member";\
								alert("Lưu thành công!");
								if(strFun!="")
									var ret = eval(strFun);
								$(eid).dialog( "close" );
							}
							else
							{
							
								$('#error').html(data).show('slow');
								$.unblockUI();
								
							}
							$.unblockUI();
						}
					);	
						
						
                    
					
				},
				'Đóng': function() 
				{
					
					$(eid).dialog( "close" );
					
				},
			}
		});
	
		
		$(eid).load("?route=gara/car/update&id="+id+"&opendialog=true",function(){
			$(eid).dialog("open");
		});	
}
function deleteitem()
{
	var answer = confirm("Bạn có muốn xóa không?")
	if (answer)
	{
		$.post("?route=gara/car/delete", 
				$("#frm_listcar").serialize(), 
				function(data)
				{
					if(data!="")
					{
						alert(data)
						window.location.reload();
					}
				}
		);
	}
}
$(document).ready(function(e) {
    viewAll();
});

$('.text').keyup(function(e) {
    searchForm();
});
$('select').change(function(e) {
    searchForm();
});
function viewAll()
{
	url = "?route=gara/car/getList";
	if("<?php echo $_GET['opendialog']?>" == "true")
	{
		url += "&opendialog=true";
	}
	$('#listmovie').html(loading);
	$('#listmovie').load(url);
}

function searchForm()
{
	var url =  "";
	if($("#frm_movie #carnumber").val() != "")
		url += "&carnumber=" + encodeURI($("#frm_listcar #carnumber").val());
	
	

	
	if("<?php echo $_GET['opendialog']?>" == "true")
	{
		url += "&opendialog=true";
	}
	$('#listmovie').html(loading);
	$('#listmovie').load("?route=gara/car/getList"+url);
}

function moveto(url,eid)
{
	$(eid).html(loading);
	$(eid).load(url);	
}
</script>